package com.seek.springevent.listen;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.seek.springevent.dao.CustomerMobileInfoDao;
import com.seek.springevent.entity.CustomerMobileInfo;
import com.seek.springevent.event.PaixuEvent;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;

@Log
@Component
public class InvokePaixListener implements ApplicationListener<PaixuEvent> {

    @Autowired
    private ExecutorService executorService;

    @Autowired
    private CustomerMobileInfoDao customerMobileInfoDao;

    @Override
    public void onApplicationEvent(PaixuEvent paixuEvent) {
        executorService.execute(()->{
            CustomerMobileInfo customerMobileInfo = customerMobileInfoDao.selectList(new EntityWrapper<CustomerMobileInfo>().eq("customer_id",paixuEvent.getCustomerId())).get(0);
            log.info("异步中的customerMobileInfo:" + JSONObject.toJSONString(customerMobileInfo));
        });
    }
}
